import shutil

import tushare as ts
from loguru import logger


def run():
    save_name = 'cal_ops/all.csv'
    # 一小时只能请求一次
    try:
        logger.info(f'正在更新 {save_name}')
        pro = ts.pro_api(token='bbc6f076aa3d2b063cb26376ad12ffd94b53864b42d2344b3aa2039f')
        data = pro.stock_basic(exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date')
        data.to_csv(save_name)
        shutil.copyfile(save_name, 'all.csv')
    except Exception as e:
        logger.warning(e)
    logger.info(f'更新完成 {save_name}')


if __name__ == '__main__':
    run()
